package com.cultraview;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

import org.opencv.core.Rect;

public class PanelRect {
	private Rect mRect;
	
	private ArrayList<Rect> mChilds;

	public PanelRect(Rect mRect, ArrayList<Rect> mChilds) {
		super();
		this.mRect = mRect;
		this.mChilds = mChilds;
	}

	public Rect getRect() {
		return mRect;
	}

	public ArrayList<Rect> getChilds() {
		return mChilds;
	}
	
	public void addChild(Rect rect){
		mChilds.add(rect);
	}
	
	public int getChildCount() {
		return mChilds.size();
	}
	public String toString() {
		return mRect.toString() + " childs:" + mChilds.size(); 
	}

	private Comparator xComparator = new Comparator() {

		@Override
		public int compare(Object arg0, Object arg1) {
			// TODO Auto-generated method stub
			return ((((Rect) arg0).x < ((Rect) arg1).x ? 1
					: (((Rect) arg0).x == ((Rect) arg1).x ? 0 : -1)));
		}

	};
	
	private Comparator yComparator = new Comparator() {

		@Override
		public int compare(Object arg0, Object arg1) {
			// TODO Auto-generated method stub
			return ((((Rect) arg0).y -5 > ((Rect) arg1).y ? 1
					: (((Rect) arg0).y -5 == ((Rect) arg1).y ? 0 : -1)));
		}

	};
	
	public void childsSort() {
		Collections.sort(mChilds, xComparator);
		Collections.sort(mChilds, yComparator);
	}
	
	public void childLocate() {
		return;
	}
}
